﻿using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FormPlugin.Local
{
    [Description("测试IBillView接口")]
    public class TestView : AbstractBillPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.EqualsIgnoreCase("ToBillView"))
            {
                //创建视图
                IBillView billView = CreateBillView.CreateView(this.Context, "PRD_PPBOM");
                ((IBillViewService)billView).LoadData();
                DynamicFormViewPlugInProxy eventProxy = billView.GetService<DynamicFormViewPlugInProxy>();
                eventProxy.FireOnLoad();
                //加载单据
                billView.Model.Load(100139);
                billView.Model.InsertEntryRow("FEntity", 0);
                var obj = billView.Model.DataObject;
                DynamicObjectCollection rows = obj["PPBomEntry"] as DynamicObjectCollection;
                for (int i = 0; i < rows.Count; i++)
                {
                    int seq = Convert.ToInt32(rows[i]["Seq"]);
                    if (seq == 1)
                    {
                        billView.Model.SetItemValueByNumber("FMaterialID2", "S2.03.005.2", i);
                        billView.Model.SetValue("FReserveType", 1, i);
                        billView.Model.SetValue("FNumerator", 1, i);
                        billView.Model.SetValue("FDenominator", 1, i);
                    }
                }
                //IDynamicFormViewService dyView = billView as IDynamicFormViewService;
                //dyView.UpdateValue("FMaterialID2", 0, "S2.03.005.2");
                //dyView.UpdateValue("FReserveType", 0, 1);
                //dyView.UpdateValue("FNumerator", 0, 1);
                //dyView.UpdateValue("FDenominator", 0, 1);
                //billView.Model.SetValue("FReserveType", 1, 0);
                //billView.Model.SetValue("FNumerator", 1, 0);
                //billView.Model.SetValue("FDenominator", 1, 0);
                //保存单据
                CreateBillView.SaveBill(billView, OperateOption.Create(), this.Context);
            }
        }
    }
}
